define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'notice/index' + location.search,
                    add_url: 'notice/add',
                    edit_url: 'notice/edit',
                    del_url: 'notice/del',
                    multi_url: 'notice/multi',
                    import_url: 'notice/import',
                    table: 'notice',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search:false,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {
                            field: 'content',
                            title: __('内容'),
                            operate: false,
                            formatter: function (value,row,index,field) {
                                if(index < 4){
                                    return "<span style='display: block;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;' data-toggle='tooltip' data-placement='bottom' title='"+row.content+"'>" + value + "</span>";
                                }else{
                                    return "<span style='display: block;overflow: hidden;text-overflow:ellipsis;white-space: nowrap;' data-toggle='tooltip' title='"+row.content+"'>" + value + "</span>";
                                }
                            },
                            cellStyle: function (value,row,index,field) {
                                return {
                                    css:{
                                        "white-space":"nowrap",
                                        "text-overflow":"ellipsis",
                                        "overflow":"hidden",
                                        "max-width":"250px",
                                    }
                                };
                            }
                        },
                        {
                            field: 'need_confirm',
                            title: __('Need_confirm'),
                            operate: '=',
                            searchList: Config.getNeedConfirm,
                            defaultValue: "",
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'user.nickname', title: __('Get_user_id')},
                        {field: 'identity_type', title: __('Identity_type'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'addtime', title: __('Addtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
